package com.zqu.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zqu.pojo.Client;
import com.zqu.service.ClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("client")
public class ClientController {
    @Autowired
    private ClientService clientService;

    @RequestMapping("findclient")
    @ResponseBody
    public Client selectById(long id){
        return clientService.selectClientById(id);
    }

    @RequestMapping("selectclientlist")
    @ResponseBody
    public PageInfo<Client> selectList(Integer pageNo,Integer pageSize){
        if(pageNo==null){
            pageNo=1;
        }
        if (pageSize==null){
            pageSize=5;
        }
        PageHelper.startPage(pageNo,pageSize);
        List<Client> list = clientService.selectList(new Client());
        PageInfo<Client> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @RequestMapping("insertclient")
    @ResponseBody
    public boolean insert(){
        return clientService.insertClient(new Client());
    }

    @RequestMapping("updateclient")
    @ResponseBody
    public boolean update(){
        return clientService.updateClient(new Client());
    }

    @RequestMapping("deleteclient")
    @ResponseBody
    public boolean delete(long id){
        return clientService.deleteClient(id);
    }

    @RequestMapping("deleteclientbyids")
    @ResponseBody
    public boolean deleteByIds(String[] ids){
        return clientService.deleteClientByIds(ids);
    }
}
